package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
public class SearchApiController {

    private final SearchService searchService;

    @Autowired
    public SearchApiController(SearchService searchService) {
        this.searchService = searchService;
    }

    /**
     * 首页频道数据
     *
     * @param category1Id
     * @return
     */
    @GetMapping("/channel/{category1Id}")
    public Result channel(@PathVariable("category1Id") Long category1Id) {
        return Result.ok(searchService.channel(category1Id));
    }

    /**
     * 专辑搜索
     *
     * @param albumIndexQuery
     * @return
     */
    @PostMapping
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery) {
        return Result.ok(searchService.search(albumIndexQuery));
    }

    /**
     * 提示词接口
     *
     * @param keywords
     * @return
     */
    @GetMapping("/completeSuggest/{keywords}")
    public Result completeSuggest(@PathVariable("keywords") String keywords) {
        return Result.ok(searchService.completeSuggest(keywords));
    }

    /**
     * 查询专辑的详细信息
     *
     * @param albumId
     * @return
     */
    @GetMapping("/{albumId}")
    public Result albumDetail(@PathVariable("albumId") Long albumId) {
        return Result.ok(searchService.albumDetail(albumId));
    }
}
